define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var site_id = Config.site_id;
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init();

            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        table: {
            first1: function () {
                // 表格1
                var table1 = $("#table1");
                table1.bootstrapTable({
                    url: 'week_special/index?site_id=1&' + location.search,
                    extend: {
                        index_url: 'week_special/index?site_id=1&' + location.search,
                        add_url: 'week_special/add',
                        edit_url: 'week_special/edit',
                        // del_url: 'week_special/del',
                        multi_url: 'week_special/multi',
                    },
                    toolbar: '#toolbar1',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'week', title: __('Type'), searchList: Config.weekList, formatter: Table.api.formatter.label, operate: false},
                            {field: 'lock_list', title: __('Lock_list'), operate: false, cellStyle: function () {return {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}}, align:"left"},
                            // {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                            {field: 'status', title: __('Status'), searchList: Config.statusList, formatter: Table.api.formatter.toggle,yes:1,no:2, operate: false},
                            {field: 'operate', title: __('Operate'), table: table1, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
                // 为表格1绑定事件
                Table.api.bindevent(table1);
            },
            first2: function () {
                // 表格2
                var table2 = $("#table2");
                table2.bootstrapTable({
                    url: 'week_special/index?site_id=2&' + location.search,
                    extend: {
                        index_url: 'week_special/index?site_id=2&' + location.search,
                        add_url: 'week_special/add',
                        edit_url: 'week_special/edit',
                        // del_url: 'week_special/del',
                        multi_url: 'week_special/multi',
                    },
                    toolbar: '#toolbar2',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'week', title: __('Type'), searchList: Config.weekList, formatter: Table.api.formatter.label, operate: false},
                            {field: 'lock_list', title: __('Lock_list'), operate: false, cellStyle: function () {return {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}}, align:"left"},
                            // {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                            {field: 'status', title: __('Status'), searchList: Config.statusList, formatter: Table.api.formatter.toggle,yes:1,no:2, operate: false},
                            {field: 'operate', title: __('Operate'), table: table2, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
                // 为表格1绑定事件
                Table.api.bindevent(table2);
            },
            first3: function () {
                // 表格3
                var table3 = $("#table3");
                table3.bootstrapTable({
                    url: 'week_special/index?site_id=3&' + location.search,
                    extend: {
                        index_url: 'week_special/index?site_id=3&' + location.search,
                        add_url: 'week_special/add',
                        edit_url: 'week_special/edit',
                        // del_url: 'week_special/del',
                        multi_url: 'week_special/multi',
                    },
                    toolbar: '#toolbar3',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'week', title: __('Type'), searchList: Config.weekList, formatter: Table.api.formatter.label, operate: false},
                            {field: 'lock_list', title: __('Lock_list'), operate: false, cellStyle: function () {return {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}}, align:"left"},
                            // {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                            {field: 'status', title: __('Status'), searchList: Config.statusList, formatter: Table.api.formatter.toggle,yes:1,no:2, operate: false},
                            {field: 'operate', title: __('Operate'), table: table3, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
                // 为表格1绑定事件
                Table.api.bindevent(table3);
            },
            first4: function () {
                // 表格4
                var table4 = $("#table4");
                table4.bootstrapTable({
                    url: 'week_special/index?site_id=4&' + location.search,
                    extend: {
                        index_url: 'week_special/index?site_id=4&' + location.search,
                        add_url: 'week_special/add',
                        edit_url: 'week_special/edit',
                        // del_url: 'week_special/del',
                        multi_url: 'week_special/multi',
                    },
                    toolbar: '#toolbar4',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'week', title: __('Type'), searchList: Config.weekList, formatter: Table.api.formatter.label, operate: false},
                            {field: 'lock_list', title: __('Lock_list'), operate: false, cellStyle: function () {return {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}}, align:"left"},
                            // {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                            {field: 'status', title: __('Status'), searchList: Config.statusList, formatter: Table.api.formatter.toggle,yes:1,no:2, operate: false},
                            {field: 'operate', title: __('Operate'), table: table4, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
                // 为表格1绑定事件
                Table.api.bindevent(table4);
            },
            first5: function () {
                // 表格5
                var table5 = $("#table5");
                table5.bootstrapTable({
                    url: 'week_special/index?site_id=5&' + location.search,
                    extend: {
                        index_url: 'week_special/index?site_id=4&' + location.search,
                        add_url: 'week_special/add',
                        edit_url: 'week_special/edit',
                        // del_url: 'week_special/del',
                        multi_url: 'week_special/multi',
                    },
                    toolbar: '#toolbar5',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'week', title: __('Type'), searchList: Config.weekList, formatter: Table.api.formatter.label, operate: false},
                            {field: 'lock_list', title: __('Lock_list'), operate: false, cellStyle: function () {return {css: {"max-width": "300px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}}, align:"left"},
                            // {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                            {field: 'status', title: __('Status'), searchList: Config.statusList, formatter: Table.api.formatter.toggle,yes:1,no:2, operate: false},
                            {field: 'operate', title: __('Operate'), table: table5, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
                // 为表格1绑定事件
                Table.api.bindevent(table5);
            },
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});